<template>
	<view class="content">
		<view>
			<u-sticky>
				<u-search 
					v-model="keyword"
					:clearabled="true"
					showAction
					placeholder="请输入公司名称"
					@change="onSearch"></u-search>
			</u-sticky>
		</view>
		
		<view class="u-m-t-30">
			<u-radio-group 
			    v-model="name"
				placement="column"
			    iconPlacement="right"
				borderBottom>
				<u-radio
					activeColor="#005aba" 
					:customStyle="{marginBottom: '8px'}"
					v-for="(item, index) in filterList"
					:key="index"
					:label="item.name"
					:name="item.name"
				>
				</u-radio>
			</u-radio-group>
		</view>
		
		<view class="btnSave">
			<u-button
				type="primary" 
				text="确定"
				color="#005aba"
				size="large"
				:customStyle="{borderRadius: '10rpx'}"
			></u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				name: '',
				keyword: '',
				list: [
					{
						name: '人保'
					},
					{
						name: '人保2'
					},
					{
						name: '人保3'
					},
					{
						name: '人保4'
					},
					{
						name: '人寿'
					},
					{
						name: '人寿2'
					},
					{
						name: '人寿3'
					},
					{
						name: '人寿4'
					},
					{
						name: '人寿5'
					},
					{
						name: '人寿12'
					},
					{
						name: '人寿13'
					},
					{
						name: '人寿14'
					},
				],
				filterList: []
			}
		},
		onShow() {
			// 权限跳转
			// let date = new Date()
			// let year = date.getFullYear()
			// let month = (date.getMonth() + 1 < 10 ? '0'+ (date.getMonth() + 1) : date.getMonth() + 1)
			// let day = (date.getDate() < 10 ? '0'+ date.getDate() : date.getDate())
			// let d = year + '-' + month + '-' + day
			// if (d == '2024-01-17') {
			// 	uni.navigateTo({
			// 		url: '/pages/error/error'
			// 	})
			// }
		},
		onLoad() {
			this.filterList = this.list
		},
		methods: {
			onSearch() {
				let key = this.keyword.toLowerCase()
				let newList = []
				if (key) {
					this.list.filter(item => {
						if (item.name.toLowerCase().indexOf(key) !== -1) {
							newList.push(item)
						}
					})
				} else {
					newList = this.list
				}
				this.filterList = newList
			},
			// 防抖原理：一定时间内，只有最后一次操作，再过wait毫秒后才执行函数
			debounce (func, wait = 500, immediate = false) {
				if (timeout !== null) clearTimeout(timeout)
				if (immediate) {
					var callNow = !timeout
					timeout = setTimeout(function () {
						timeout = null
					}, wait)
					if (callNow) typeof func === 'function' && func()
				} else {
					timeout = setTimeout(function () {
						typeof func === 'function' && func()
					}, wait)
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		height: 100vh;
		padding: 30rpx 30rpx calc(30rpx + var(--status-bar-height));
		overflow-y: auto;
	}
	.btnSave {
		position: fixed;
		left: 30rpx;
		right: 30rpx;
		bottom: var(--status-bar-height);
		z-index: 9;
	}
</style>
